﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace quickReminder
{
    public partial class FormUpdateStatus : Form
    {
        public class ReminderInitializedEventArgs : EventArgs
        {
            private ESLReminder.Reminder m_Reminder;
            public ESLReminder.Reminder Reminder
            {
                get { return m_Reminder; }
            }
            public ReminderInitializedEventArgs(ESLReminder.Reminder reminder)
            {
                m_Reminder = reminder;
            }
        }
        public event EventHandler<ReminderInitializedEventArgs> ReminderInitialized;
        public FormUpdateStatus()
        {
            InitializeComponent();
        }

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            ESLReminder.Reminder reminder = new ESLReminder.Reminder();
            e.Result = reminder;
        }

        private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            EventHandler<ReminderInitializedEventArgs> h = ReminderInitialized;
            if (h != null)
                h(this, new ReminderInitializedEventArgs((ESLReminder.Reminder)e.Result));
            lStatus.Text = "Checking for updates";
            Text = "Checking for updates";
            this.WindowState = FormWindowState.Minimized;
        }

        private void FormUpdateStatus_Shown(object sender, EventArgs e)
        {
            backgroundWorker1.RunWorkerAsync();
        }

        private void automaticUpdater1_CheckingFailed(object sender, wyDay.Controls.FailArgs e)
        {
            Console.WriteLine("Checking failed");
            Text = "Checking failed";
            lStatus.Text = e.ErrorTitle;
            //this.WindowState = FormWindowState.Normal;
        }

        private void automaticUpdater1_UpdateAvailable(object sender, EventArgs e)
        {
            Console.WriteLine("Update available");
            Text = "Update available";
            lStatus.Text = "";
            //this.WindowState = FormWindowState.Normal;
        }

        private void automaticUpdater1_UpToDate(object sender, wyDay.Controls.SuccessArgs e)
        {
            Console.WriteLine("Up to date");
            Close();
        }
    }
}
